package com.dehui.traders.ui.base;

import android.content.Context;
import android.databinding.ViewDataBinding;
import android.view.View;
import android.widget.TextView;
import com.dehui.traders.R;

import me.goldze.mvvmhabit.base.BaseActivity;
import me.goldze.mvvmhabit.base.BaseViewModel;
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;

public abstract class AppActvity<V extends ViewDataBinding, VM extends BaseViewModel> extends BaseActivity<V,VM>{


    public void initToolbar(String leftName,String title){
        View toolbar = findViewById(R.id.toolbar);
        if (toolbar == null)
            return;
        toolbar.findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        TextView tvTitle = toolbar.findViewById(R.id.tv_title);
        tvTitle.setText(title);

        TextView tvBackName = toolbar.findViewById(R.id.tv_back_name);
        if (tvBackName != null){
            tvBackName.setText(leftName);
            tvBackName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onBackPressed();
                }
            });
        }
    }

    public void initToolbar(String title){
        initToolbar("",title);
    }

    public void initToolbarValue(int left,int title){
        initToolbar(getString(left),getString(title));
    }

    public void initToolbarValue(int titleValue){
        initToolbar(getString(titleValue));
    }

    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
    }


}
